/**
 * Created by chen on 18/5/22.
 */

window.onload = function(){
  $.ajax({
    type: 'GET',
    url: "/allItems",
    success: function(data){
      console.log(data);
      var tpl = document.getElementById('tpl').innerHTML;
      document.getElementById('shopping_list_info').innerHTML = template(tpl, {list:data});
    }
  });
  $.ajax({
    type: 'GET',
    url: "/allCartList",
    success: function(data){
      console.log(data);
      var allCartList = data;
      getCartNum(allCartList);
    }
  });

  //var allCartList = JSON.parse(localStorage.getItem("cartList"))||[];
  //
  //getCartNum(allCartList);
};
function addItemToCart()
{
  var id=$("#"+event.target.id)[0].id;
  $.ajax({
    type: 'POST',
    url: "/addItemToCart",
    data:{barcode:id},
    success: function(data){
      console.log(data);
      //统计购物车数量
      getCartNum(data);
    }
  });
}
